using SqlSugar;
using SqlsugarService.Domain.Common;
using System;

namespace SqlsugarService.Domain.QualityInspection
{
    /// <summary>
    /// 质检方案与报工质检关联实体类（中间表）
    /// 用于建立质检方案和报工质检之间的多对多关系，并提供版本控制功能
    /// </summary>
    [SugarTable("QualityInspectionPlanWorkReport")]
    public class QualityInspectionPlanWorkReportEntity : BaseEntity
    {
        [SugarColumn(IsPrimaryKey = true)]
        public Guid Id { get; set; } = Guid.NewGuid();

        #region 关联外键
        /// <summary>
        /// 质检方案Id
        /// </summary>
        [SugarColumn(IsNullable = false)]
        public Guid QualityInspectionPlanId { get; set; }

        /// <summary>
        /// 报工质检Id
        /// </summary>
        [SugarColumn(IsNullable = false)]
        public Guid WorkReportInspectionId { get; set; }
        #endregion

        #region 版本控制
        /// <summary>
        /// 版本号
        /// 每次修改关联关系时递增，用于跟踪变更历史
        /// </summary>
        [SugarColumn(DefaultValue = "1")]
        public int Version { get; set; } = 1;

        /// <summary>
        /// 版本描述
        /// 记录本次版本变更的原因或内容
        /// </summary>
        [SugarColumn(IsNullable = true, Length = 500)]
        public string? VersionDescription { get; set; }

        /// <summary>
        /// 是否为当前有效版本
        /// true: 当前有效版本, false: 历史版本
        /// </summary>
        [SugarColumn(DefaultValue = "true")]
        public bool IsCurrentVersion { get; set; } = true;

        /// <summary>
        /// 版本生效时间
        /// </summary>
        public DateTime EffectiveTime { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 版本失效时间
        /// 当创建新版本时，旧版本的失效时间会被设置
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public DateTime? ExpiryTime { get; set; }
        #endregion       

        /// <summary>
        /// 备注信息
        /// </summary>
        [SugarColumn(IsNullable = true, Length = 1000)]
        public string? Remark { get; set; }
    }
}